<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        .box{
            width:100px;
            height:100px;
            background-color: black;
        }
    </style>
</head>
<body>
    <button>按钮</button>
    <div class="box"></div>
    <script>
        let btn = document.querySelector("button");
        let box = document.querySelector(".box");

        // 事件监听函数 on是绑定的意思 btn按钮绑定click
        box.onmouseenter = function(){
            console.log("blue")
            this.style.backgroundColor = "blue";
        }
        box.onmouseleave = function(){
            console.log("red")
            this.style.backgroundColor = "red";
        }
       
        btn.onclick = function(){
            console.log("yellow")
            box.style.backgroundColor = "yellow"
        }
    </script>
</body>
</html>